<?php

/**************************************************************************
* Source File	:  Article.php
* Author                   :  Marian
* Project name         :  Accueil Win'Design version 14* Created                 :  20/01/2015
* Modified   	:  20/01/2015
* Description	:  Definition of the class Article
**************************************************************************/




class Article 			
{
	//Attributes
		
	Private $ID; 
	Private $titre; 
	Private $contenu; 
	Private $datedebutvalide;
	Private $datefinvalide;
	Private $UneRubrique;
	
	//Seters
	
	public function __set($propriete, $valeur) {
	
		switch ($propriete) {
			case 'titre' : {
				$this->titre = $valeur;
				break;
			}
	
			case 'contenu' : {
				$this->contenu = $valeur;
				break;
			}
				
			case 'datedebutvalide' : {
				$this->datedebutvalide = $valeur;
				break;
			}
			
			case 'datefinvalide' : {
				$this->datefinvalide = $valeur;
				break;
			}
			
			case 'UneRubrique' : {
				$this->UneRubrique = $valeur;
				break;
			}
		}
	}
	//Operations
	public function __construct($vID, $vtitre, $vcontenu, $vUneRubrique, $vdatedebutvalide, $vdatefinvalide)
	{
		/*$this->IDImage = trouverId($vtitre, $vfichier, $vUnAlbum);*/
		$this->ID = $vID;
		$this->titre = $vtitre;
		$this->contenu = $vcontenu;
		$this->UneRubrique = $vUneRubrique;
		$this->datedebutvalide = $vdatedebutvalide;
		if ($vdatefinvalide > $vdatedebutvalide)
		{
		$this->datefinvalide = $vdatefinvalide;
		}
		else
		{
			$this->datefinvalide = NULL;
		}
	}
	
	public function PDO ()
	{
		require_once (dirname(getcwd()).'/MyPDO.php');
		require_once 'PreparationREQArticle.php';
		$PrepREQ = new PreparationREQArticle(new MyPDO());
		return $PrepREQ;
	}
	
	public function NewArticle()
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->insert($this->titre, $this->UneRubrique, $this->contenu, $this->datedebutvalide, $this->datefinvalide);	
	}
	 
	public function ModifierContenu($vNewContenu)
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->UpdateContenu($vNewContenu, $this->ID);
		
	}
	
	public function ModifierRubrique($vNewRubrique)
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->UpdateIdRubrique($vNewRubrique, $this->ID);
	}
	
	public function ModifierTitre($vnewTitre)
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->UpdateTitre($vnewTitre, $this->ID);
	
	}
	
	public function ModifierDateDebutValide($vnewDateDebutValide)
	{
		date_default_timezone_set('Europe/Paris');
		$date = date('d/m/Y h:i:s');
		$vretour = null;
		if ($vnewDateDebutValide >= $date && $vnewDateDebutValide < $this->datefinvalide)
		{
		$PrepREQ = $this->PDO();
		$PrepREQ->UpdateDateDebutValide($vnewDateDebutValide, $this->ID);
		}
		else
		{
			$vretour = 'Date et heure inférieur à l\'heure et la date actuelle';
		}
		return $vretour;
	}
	
	public function ModifierDateFinValide($vnewDateFinValide)
	{
		date_default_timezone_set('Europe/Paris');
		$date = date('d/m/Y h:i:s');
		$vretour = null;
		if ($vnewDateFinValide >= $date)
		{
			$PrepREQ = $this->PDO();
			$PrepREQ->UpdateDateFinValide($vnewDateFinValide, $this->ID);
		}
		else
		{
			$vretour = 'Date et heure inférieur à l\'heure et la date actuelle';
		}
		return $vretour;
	}
	
	public function getDateFin()
	{
		if ($this->datefinvalide != NULL)
		{
			return date('d-m-Y', strtotime($this->datefinvalide));
		}
		else
		{
			return 'Aucune date de fin';
		}
	}
	
	public function getDatedebut()
	{
		if ($this->datedebutvalide != NULL)
		{
			return date('d-m-Y', strtotime($this->datedebutvalide));
		}
		else
		{
			return 'Aucune date de debut';
		}
	}
	
	
	
	
	public function TrouverID()
	{
		$PrepREQ =$this->PDO();
		return $PrepREQ->TrouverID($this->titre, $this->UneRubrique, $this->datedebutvalide, $this->datefinvalide);
	
	}
	
	public function ArrayAllArticle ()
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->SelectAll();
	}
	
	public function SupprimerArticle()
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->SupprimerArticle($this->ID);
	}
	

} // End Class Article


?>

